#ifndef CARETAKER_H
#define CARETAKER_H
//月光宝盒

#include"originator.h"
#include<vector>
class PandoraBox{
public:
    PandoraBox(Life *life):m_pLife(life){}
    ~PandoraBox(){
        //清理所有备份
        for(auto str:m_history)
            delete str;
        m_history.clear();
    }
    //保存备份
    void Save(){
        cout<<"Save....."<<endl;
        m_history.push_back(m_pLife->CreateMemento());
    }
    //穿越到上一时刻
    void Undo(){
        cout<<"Undo....."<<endl;
        m_pLife->SetMemento(m_history.back());
        m_history.pop_back();
    }
    void Undo(int index){
        if(m_history.size()!=0&&index<m_history.size()){
            m_pLife->SetMemento(m_history.at(index));
        }

    }
private:
    Life *m_pLife;
    vector<DateTime*> m_history;
};

#endif // CARETAKER_H
